package com.ruoyi.parking.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.parking.domain.ParkRules;
import com.ruoyi.parking.service.IParkRulesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 收费规则Controller
 * 
 * @author chenkai
 * @date 2025-02-08
 */
@RestController
@RequestMapping("/parking/rules")
public class ParkRulesController extends BaseController
{
    @Autowired
    private IParkRulesService parkRulesService;

    /**
     * 查询收费规则列表
     */
    @PreAuthorize("@ss.hasPermi('parking:rules:list')")
    @GetMapping("/list")
    public TableDataInfo list(ParkRules parkRules)
    {
        startPage();
        List<ParkRules> list = parkRulesService.selectParkRulesList(parkRules);
        return getDataTable(list);
    }

    /**
     * 导出收费规则列表
     */
    @PreAuthorize("@ss.hasPermi('parking:rules:export')")
    @Log(title = "收费规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ParkRules parkRules)
    {
        List<ParkRules> list = parkRulesService.selectParkRulesList(parkRules);
        ExcelUtil<ParkRules> util = new ExcelUtil<ParkRules>(ParkRules.class);
        util.exportExcel(response, list, "收费规则数据");
    }

    /**
     * 获取收费规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('parking:rules:query')")
    @GetMapping(value = "/{rulesId}")
    public AjaxResult getInfo(@PathVariable("rulesId") Long rulesId)
    {
        return success(parkRulesService.selectParkRulesByRulesId(rulesId));
    }

    /**
     * 新增收费规则
     */
    @PreAuthorize("@ss.hasPermi('parking:rules:add')")
    @Log(title = "收费规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParkRules parkRules)
    {
        return toAjax(parkRulesService.insertParkRules(parkRules));
    }

    /**
     * 修改收费规则
     */
    @PreAuthorize("@ss.hasPermi('parking:rules:edit')")
    @Log(title = "收费规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ParkRules parkRules)
    {
        return toAjax(parkRulesService.updateParkRules(parkRules));
    }

    /**
     * 删除收费规则
     */
    @PreAuthorize("@ss.hasPermi('parking:rules:remove')")
    @Log(title = "收费规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rulesIds}")
    public AjaxResult remove(@PathVariable Long[] rulesIds)
    {
        return toAjax(parkRulesService.deleteParkRulesByRulesIds(rulesIds));
    }
}
